<include file="Public/min-header"/>
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
  <include file="Public/breadcrumb"/>
  <style type="text/css">
  	.table input{display: nones;}
	#biaozhu{cursor: pointer;}
  </style>
   
  <section class="content">
    <div class="container-fluid">
      <div class="panel panel-default">
        <div class="panel-heading"> 
          <h3 class="panel-title"><i class="fa fa-list"></i>PDA收款跟踪</h3>
        </div>
        <div class="panel-body">    
		<div class="navbar navbar-default">
                <form id="search-form2" class="navbar-form form-inline"  method="get" action="{:U('pda')}">
                <div class="form-group">
                  <div class="input-group">
                    <input type="text" class="form-control" id="order_sn" placeholder="订单号" value="{$Think.request.order_sn}" name="order_sn" />
                  </div>
					<div class="input-group">
						<input type="text" class="form-control" id="driver" placeholder="司机" value="{$Think.request.driver}" name="driver" style="width: 100px;"/>
					</div>
                  <div class="input-group">
                    <input type="text" class="form-control" id="shanghu" placeholder="商户名" value="{$Think.request.shanghu}" name="shanghu" style="width: 100px;"/>
                  </div>
				  <div class="input-group">
				    <input type="text" class="form-control" id="kehu" placeholder="客户名" value="{$Think.request.kehu}" name="kehu" style="width: 100px;"/>
				  </div>
				  <div class="form-group">
				      <div class="input-group">
				          <input type="text" name="biaoshi" placeholder="线路" id="input-order-id" class="form-control" value="{$Think.request.biaoshi}" style="width: 100px;">
				      </div>
				  </div>
				<div class="form-group">
				                  <select name="shoukuan" id="shoukuan" class="form-control">
									<?php
										if(I('shoukuan')=='0'){
											echo '<option value="">全状态</option>
											<option value="0" selected="selected">未收款</option>
									<option value="1">已收款</option>';
									}elseif(I('shoukuan')=='1'){
										echo '<option value="">全状态</option>
										<option value="0">未收款</option>
										<option value="1" selected="selected">已收款</option>';
									}else{
										echo '<option value="" selected="selected">全状态</option>
										<option value="0">未收款</option>
										<option value="1">已收款</option>';
									}
									?>
				                  </select>
				                </div>

					<div class="form-group">
						<select name="tag" id="tag" class="form-control">
							<?php
							if(I('tag')=='1'){
								echo '<option value="">是否回款</option>
							<option value="1" selected="selected">未回款</option>
							<option value="2">已回款</option>';
							}elseif(I('tag')=='2'){
							echo '<option value="">是否回款</option>
							<option value="1">未回款</option>
							<option value="2" selected="selected">已回款</option>';
							}else{
							echo '<option value="" selected="selected">是否回款</option>
							<option value="1">未回款</option>
							<option value="2">已回款</option>';
							}
							?>
						</select>
					</div>
								


                   <!--<div class="input-group margin" style="width: 250px;">
                  	<div class="input-group-addon">
                        入库时间<i class="fa fa-calendar"></i>
                    </div>
                       <input type="text" id="start_time" value="{$timegap}" autocomplete="off" name="timegap" class="form-control pull-right">
                  </div>-->
					<div class="input-group margin" style="width: 250px;">
						<div class="input-group-addon">
							出库时间<i class="fa fa-calendar"></i>
						</div>
						<input type="text" id="chuku_time" value="{$timegap}" autocomplete="off" name="chuku_time" class="form-control pull-right">
					</div>

                </div>
                <div class="form-group">
					<button type="button" style="margin-left:20px " class="btn btn-primary pull-right" id="daochu"><i class="fa fa-file-excel-o"></i>&nbsp;导出excel</button>

					<button class="btn btn-primary" id="button-filter search-order" type="submit"><i class="fa fa-search"></i> 筛选</button>
                </div><br/><span style="color: red;">提示：特殊订单如果司机未回款，实回款填0.001。总部与分部对账期间禁止确认收款！</span>
                </form>
			
          </div>
                        
          <div id="ajax_return"> 
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
								<th class="sorting text-center">选择</th>
								<th class="sorting text-center">订单号</th>
                                <th class="sorting text-center">司机</th>
                                <!-- <th class="sorting text-center">操作员</th> -->
								<th class="sorting text-center">商户名</th>
                                <th class="sorting text-center">客户名</th>
								<th class="sorting text-center">优惠金额</th>
								<th class="sorting text-center">订单价</th>
								<?php if(session('fenbu_id')==0) { ?>
								<th class="sorting text-center" style="color:red;">实回款</th>
								<?php } ?>
								<th class="sorting text-center">平台扣点</th>
								<th class="sorting text-center">线路</th>
<!--								<th class="sorting text-center">在线支付</th>-->
								<th class="sorting text-center">应付金额</th>
								<th class="sorting text-center">包装件数</th>
                                <th class="sorting text-center">入库时间</th>
                                <th class="sorting text-center">出库时间</th>
                                <th class="sorting text-center">状态/标注</th>
                                <th class="sorting text-center">操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            <volist name="list" id="v">
                                <tr>
									<td class="text-center" id="biaozhus" rel="{$v.order_id}|{$v.store_id}">
										<input type="checkbox" name="alluser_id[]" title="批量收款" value="{$v.order_id}|{$v.store_id}">
										</td>
									<td class="text-center">
										<a href="javascript:" id="chakan" rel="{$v.order_id}">
										{$v.order_sn}<?php if($v['dai_type'] == 2) echo '<span style="color:#ff9800">特殊</span>'?>
										</a></td> 
                                    <td class="text-center">
										{$v.driver_name}
                                    </td>
                                    <!-- <td class="text-center">
                                             {$v.user_name}
                                    </td> -->
									<td class="text-center">{$v.store_name}</td>
                                    <td class="text-center">{$v.consignee}（{$v.company}）</td>
									</td>
									<td class="text-center"><span style="color:#f39c12;">{$v.coupon_price}</span></td>
									<td class="text-center"><span style="color:#f39c12;">{$v.order_amount}</span></td>
									<?php if(session('fenbu_id')==0) { ?>
									<td class="text-center">
										<if condition="$v['is_checkout'] eq '0'">
										<input type="text" onchange="updateSort('order','order_id','{$v.order_id}','shi_price',this)" maxlength="10" value="{$v.shi_price}" class="input-sm" style="width: 80px;text-align: center;">
										<else/>
										<span style="color:#f39c12;">{$v.shi_price}</span>
										</if>
										</td>
									<?php } ?>
									<td class="text-center"><span style="color:blue;">{:sanwei($v['pprice'])}</span></td>
									<td class="text-center">{$v.biaoshi_xian}</td>
									<!--<td class="text-center"><?php
									if($v['pay_status']==1)
										echo '<span style="color:green">已支付</span>';
										else
										echo '<span style="color:red">未支付</span>';
										?></td>-->
									<td class="text-center">
										<if condition="$v['shi_price'] eq '0'">
										<b style="color: red;">{:sanwei($v['order_amount']-$v['pprice'])}</b>
										<else/>
										<b style="color: red;">{:sanwei($v['shi_price']-$v['pprice'])}</b>
										</if>
										</td>
									<td class="text-center"><b>{$v.jian_count} / 件</b>
									</td>
									<td class="text-center"><span><?php echo date('Y-m-d H:i:s',$v['ruku_last_time']); ?></span></td>
									<td class="text-center"><span><?php echo date('Y-m-d H:i:s',$v['chuku_last_time']); ?></span></td>

                                    <td class="text-center">
                                        <if condition="$v[status_c] eq '0'"><span style="color: red;">未出库</span></if>
                                        <if condition="$v[status_c] eq '1'"><span style="color: green;">已出库</span></if>
										<if condition="$v['tag_price'] eq '0'">
									    &nbsp;（<i class="glyphicon glyphicon-flag" id="biaozhu" rel="0" title="标注未回款单据">未回款</i>）
										<else/>
										&nbsp;（<i class="glyphicon glyphicon-flag" id="biaozhu" rel="1" title="恢复未回款单据" style="color:red;">未回款</i>）
										</if>
                                    </td>
                                    <td class="text-center" id="tr_{$v.order_id}">
										<?php
										if($pda_open==1){
										?>
										<if condition="$v['is_checkout'] eq '0'">
											<a href="javascript:" data-toggle="tooltip" rel="{$v.order_id}" rev="{$v.store_id}" class="btn btn-primary" id="queren">确定收款 <i class="fa fa-pencil"></i></a>
											<else/>
											<a href="javascript:" data-toggle="tooltip" style="pointer-events:none;color:green" class="btn btn-default" id="queren">已经收款 <i class="fa fa-check"></i></a>
											</if>
											<?php
											}else{
												echo '<span style="color:red">对账中..</span>';
											}
											?>
                                    </td> 
                                </tr>
                            </volist>
                            </tbody>
							<tbody>
								<tr style="font-size: 16px;color: red;">
									<td colspan="5" align="right">合计：</td>
									<td align="center">￥{$xprice}</td>
									<?php if(session('fenbu_id')==0) { ?>
									<td align="center"></td>
									<?php }?>
									<td align="center">￥{$pprice}</td>
									<td align="center"></td>
									<td align="center">￥{$yprice}</td>
									<td colspan="4"></td>
								</tr>
							</tbody>
                        </table>
                    </div>
                
                <div class="row">
                    <div class="col-sm-6 text-left">
                        全选
                        <input type="checkbox" onclick="$('input[name=\'alluser_id\[\]\']').prop('checked', this.checked);">
                        <button id="act_button" type="button" onclick="act_submit();" class="btn btn-primary" style="margin-left:15px;"><i class="fa"></i> 批量收款</button>
                    </div>
                    <div class="col-sm-6 text-right">{$show}</div>
                </div>
          </div>
        </div>
      </div>
    </div>
    <!-- /.row --> 
  </section>
  <!-- /.content --> 
</div>
<!-- /.content-wrapper --> 
 <script>
	$(document).ready(function() {
		$('#start_time').daterangepicker({
			format:"YYYY-MM-DD HH:mm",
			singleDatePicker: false,
			showDropdowns: true,
			minDate:'2021-01-01 00:00',
			maxDate:'2030-01-01 00:00',
			startDate:'{:date("Y-m-d")} 00:00',
		    showWeekNumbers: true,
		    timePicker: true,
		    timePickerIncrement: 1,
		    timePicker12Hour: false,
		    ranges: {
		       '今天': [moment(), moment()],
		       '昨天': [moment().subtract('days', 1), moment().subtract('days', 1)],
		       '最近7天': [moment().subtract('days', 6), moment()],
		       '最近30天': [moment().subtract('days', 29), moment()],
		       '上一个月': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
		    },
		    opens: 'left',
		    buttonClasses: ['btn btn-default'],
		    applyClass: 'btn-small btn-primary',
		    cancelClass: 'btn-small',
		    locale : {
		        applyLabel : '确定',
		        cancelLabel : '取消',
		        fromLabel : '起始时间',
		        toLabel : '结束时间',
		        customRangeLabel : '自定义',
		        daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
		        monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
		        firstDay : 1
		    }
		});

		$('#chuku_time').daterangepicker({
			format:"YYYY-MM-DD HH:mm",
			singleDatePicker: false,
			showDropdowns: true,
			minDate:'2021-01-01 00:00',
			maxDate:'2030-01-01 00:00',
			startDate:'{:date("Y-m-d")} 00:00',
			showWeekNumbers: true,
			timePicker: true,
			timePickerIncrement: 1,
			timePicker12Hour: false,
			ranges: {
				'今天': [moment(), moment()],
				'昨天': [moment().subtract('days', 1), moment().subtract('days', 1)],
				'最近7天': [moment().subtract('days', 6), moment()],
				'最近30天': [moment().subtract('days', 29), moment()],
				'上一个月': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
			},
			opens: 'left',
			buttonClasses: ['btn btn-default'],
			applyClass: 'btn-small btn-primary',
			cancelClass: 'btn-small',
			locale : {
				applyLabel : '确定',
				cancelLabel : '取消',
				fromLabel : '起始时间',
				toLabel : '结束时间',
				customRangeLabel : '自定义',
				daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
				monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
				firstDay : 1
			}
		});

	$(".table #biaozhu").click(function(){
		layer.load();
		var obj=$(this).parent().parent();
		var zhi=$(this).attr('rel');var order_id=obj.find('#chakan').attr('rel');var new_rel='';
		if(zhi=='0'){
			new_rel='1';
			obj.find('#biaozhus').html('');
			$(this).css('color','red');$(this).attr('rel',new_rel);
		}else{
			new_rel='0';
			var xuanzhe=obj.find('#biaozhus').attr('rel');
			obj.find('#biaozhus').html('<input type="checkbox" name="alluser_id[]" title="批量收款" value="'+xuanzhe+'">');
			$(this).css('color','#000');$(this).attr('rel',new_rel);
		}
		$.post('/index.php/Admin/Finance/pda',{biaozhu:'biaozhu',order_id:order_id,tag_price:new_rel},function(res){
			layer.closeAll('loading');
		});
	});
	
	$(".table #queren").click(function(){
		var myid=$(this).attr('rel');
		var store_id=$(this).attr('rev');
		var obj=$(this).parent();
		var than=$(this);
		layer.confirm('确定收款吗？确认收款后会结算给商家。', {
		  btn: ['确定','取消'] //按钮
		}, function(){
			$.post('/index.php/Admin/Finance/pda',{action:'yes',order_id:myid,store_id:store_id},function(res){
				if(res==''){
					layer.msg('收款&结算成功！', {icon:6});
					than.remove();
					obj.html('<a href="javascript:" data-toggle="tooltip" style="pointer-events:none;color:green" class="btn btn-default" id="queren">已经收款 <i class="fa fa-check"></i></a>');
				}else{
					layer.msg('收款失败！对账中，禁止收款！', {icon:5});
				}
			});
			
		});
	});
		$("#daochu").click(function(){
			var order_sn=$("#order_sn").val();
			var kehu=$("#kehu").val();
			var shanghu=$("#shanghu").val();
			var pda=$("#pda").val();
			var tag=$("#tag").val();
			var start_time=$("#start_time").val();
			var shoukuan=$("#shoukuan").val();
			var chuku_time=$("#chuku_time").val();
			var driver=$("#driver").val();

			location.href="/index.php/Admin/Finance/export_pda?order_sn="+order_sn+"&kehu="+kehu+"&shanghu="+shanghu+"&pda="+pda+"&tag="+tag+"&shoukuan="+shoukuan+"&timegap="+start_time+"&chuku_time="+chuku_time+"&driver="+driver;
		})
$(".table-responsive #chakan").click(function(){
		var myrel=$(this).attr('rel');
		var myrul='/index.php/Admin/order/detail/order_id/'+myrel;//+myrel;
			layer.open({
			  type: 2,
			  title:'订单信息',
			  shadeClose: true, //点击遮罩关闭
			  skin: 'layui-layer-rim', //加上边框
			  area: ['920px', '620px'], //宽高
			  content: myrul
		})
    });
});

    function get_select_order_id_str() {
        if ($('input[name="alluser_id\[\]"]:checked').length == 0)
            return false;
        var goods_arr = Array();
        $('input[name="alluser_id\[\]"]:checked').each(function () {
            goods_arr.push($(this).val());
        });
        var order_id_str = goods_arr.join(',');
        return order_id_str
    }
	
    //批量操作提交
    function act_submit() {
        //prompt层
        var ids = get_select_order_id_str();
        if (ids == false) {
            layer.alert('请勾选要操作的订单', {icon: 2});
            return;
        }
console.log(ids);
		layer.confirm('确定收款吗？确认收款后会结算给商家。', {
		  btn: ['确定','取消'] //按钮 
		}, function(){
			$.post('/index.php/Admin/Finance/pda_piliang',{action:'yes',datas:ids},function(res){
				if(res!=''){
					res=res.slice(0,res.length-1);
					res=res.split(',');
					for(var i=0;i<res.length;i++){
						$('.table-bordered #tr_'+res[i]).html('<a href="javascript:" data-toggle="tooltip" style="pointer-events:none;color:green" class="btn btn-default" id="queren">已经收款 <i class="fa fa-check"></i></a>');
					}
					layer.msg('收款&结算成功！', {icon:6},function(){});
				}else{
					layer.msg('收款失败！对账中，禁止收款！', {icon:5});
				}
			});
			
		});
    }
</script>
</body>
</html>